package edu.hgnc.populateBean;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * p 19节 1:14:20有用到；
 *
 * 自己扩展可以去  AbstractAutowireCapableBeanFactory  1600行左右  "!mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()" 方法
 */
@Component  // 把它添加到容器中 或者用配置文件bean注入进去
public class PersonInstantiationAwareBeanPostProcessor  implements InstantiationAwareBeanPostProcessor {

	private static final Log logger = LogFactory.getLog(PersonInstantiationAwareBeanPostProcessor.class);


	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		logger.debug("PersonInstantiationAwareBeanPostProcessor--------被调用执行---------");
		logger.debug("PersonInstantiationAwareBeanPostProcessor--------beanName---------"+beanName);
		People people = null;
		if (bean instanceof People){
			people = (People) bean;
			people.setName("张三");
			// return true;
			return true;
		}else {
			// true
			// return false;
			// return true;
			return true;
		}
	}
}
